<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%ns_department}}".
 *
 * @property integer $department_id
 * @property string $title
 *
 * @property NsProfessional[] $nsProfessionals
 */
class Department extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ns_department}}';
    }

    /**
     * @TODO  : 获取所有AR对象ID=>title数组
     * @param : 
     * @return: array(id => title)
     * @author: Ray
     * @date  : 2014-09-26
     */
    public static function getDataList()
    {
        $model = static::find()->all();
        foreach($model as $elem)
        {
            $result[$elem->getPrimaryKey()] = $elem->title;
        }
        if(!isset($result))
        {
            $result = array();
        }
        return $result;
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['title'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'department_id' => Yii::t('Department', 'Department ID'),
            'title' => Yii::t('Department', 'Title'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getNsProfessionals()
    {
        return $this->hasMany(NsProfessional::className(), ['department_id' => 'department_id']);
    }
}
